﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;


//2012年12月19日 21:16:54
//本静态类的作用是产生新的sitemap



namespace NuaTarDoneng
{
    public static class GenerMap
    {
        public static void Mysitemap(System.Web.UI.Page page)
        {
            File.Delete(page.Server.MapPath("~/sitemap/sitemap_Article.xml"));
            FileStream fs = new FileStream(page.Server.MapPath("~/sitemap/sitemap_Article.xml"), FileMode.Create);
            StreamWriter wr = new StreamWriter(fs);
            SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
            SqlCommand cmd=cnn.CreateCommand();
            cmd.CommandText="select * from [blogs] where blogID <>'LinkUp' order by blogTime desc";
            cnn.Open();
            wr.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n");
            SqlDataReader rd = cmd.ExecuteReader();
            while (rd.Read())
            {
                string ac = "<url>\r\n<loc>http://www.nuatar.com/Article.aspx?id=xx</loc>\r\n<lastmod>dd</lastmod>\r\n<changefreq>daily</changefreq>\r\n<priority>0.8</priority>\r\n</url>\r\n";

                wr.Write(ac.Replace("xx",rd["blogID"].ToString()).Replace("dd",DateTime.Parse(rd["blogTime"].ToString()).ToString("yyyy-MM-dd")));
            }
            wr.Write("</urlset>");
            wr.Flush();
            wr.Close();
            cnn.Close();
        }
    }
}